home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / mega src / TN 1 - CodeWarrior < prev   
Encoding:
Text File  |  1994-08-26  |  2.4 KB  |  124 lines  |  [TEXT/ttxt]

  1. ===========================================================================
  2.  
  3. Number 1 - Building Commands Using CodeWarrior
  4.  
  5. Revisions:    Aug. 26, 1994
  6.  
  7. nShell(tm) Technical Note
  8.  
  9. ===========================================================================
  10.  
  11. Early releases of the nShell contained sample code for the Think C development environment.  This Note describes the changes required to build these commands under the CodeWarrior environment.
  12.  
  13. Examples
  14. ========
  15.  
  16. Example projects have been released in a package called "nShell(tm) CodeWarrior Examples".  This package contains source code as well as CodeWarrior project files set up to generate nShell resources.
  17.  
  18. The Project File
  19. ================
  20.  
  21. Recommended "Preferences" are as follows:
  22.  
  23. Language
  24. --------
  25.  
  26. Factory Settings
  27.  
  28. Warnings
  29. --------
  30.  
  31. Factory Settings
  32.  
  33. Processor
  34. ---------
  35.  
  36. Code Model: Small
  37. Struct Alignment: 68K
  38.  
  39. (no boxes checked)
  40.  
  41. Linker
  42. ------
  43.  
  44. MacsBugs Symbols: New Style
  45.  
  46. ( ) Generate SYM File
  47. ( ) Generate Link Map
  48. (*) Generate A6 Stack Frames
  49. ( ) The Debugger(tm) Aware
  50.  
  51. (*) Link Single Segment
  52. (*) Fast Link
  53.  
  54. Project
  55. -------
  56.  
  57. Project Type: Code Resource
  58.  
  59. File Name: command_name
  60. Sym Name:
  61. Resource name: command
  62. Header Type: Standard
  63.  
  64. ( ) Multi Segment
  65. (*) Display Dialog
  66. ( ) Merge to File
  67.  
  68. ResType: NSHC  ResID: 16000
  69. Creator: NSHA  TYPE:  NSHC
  70.  
  71. Resource Flags: none
  72.  
  73. Source Changes
  74. ==============
  75.  
  76. CodeWarrior resources need a couple lines to set up and restore the A4 register.  We recommend adding these lines with #ifdef(s), so that source code can be built under Think C, as well as CodeWarrior:
  77.  
  78. Headers:
  79.  
  80. #ifdef __MWERKS__
  81. #include <A4Stuff.h>
  82. #endif
  83.  
  84. Main:
  85.  
  86. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  87. {
  88. #ifdef __MWERKS__
  89.     long oldA4  = SetCurrentA4();
  90. #endif
  91.     
  92. ( code for the command )
  93.  
  94. #ifdef __MWERKS__
  95.     SetA4(oldA4);
  96. #endif
  97. }
  98.  
  99. It is vital that the "SetA4" line execute before exiting.  This means that "return" statements should be avoided in the main, or that they be combined with a "SetA4":
  100.  
  101. if (error) {
  102.     #ifdef __MWERKS__
  103.     SetA4(oldA4);
  104.     #endif
  105.     return;
  106.     }
  107.  
  108. An alternative is to use goto(s) and labels:
  109.  
  110. If (error) goto Exit;
  111.  
  112. ....
  113. Exit:
  114. #ifdef __MWERKS__
  115.     SetA4(oldA4);
  116. #else
  117.     ;
  118. #endif
  119.  
  120. The #else clause is included so that Think C won't choke on an empty label.
  121.  
  122. In other aspects, commands are identical to the Think C versions.  See the nShell Programmer's Guide for more information.
  123.  
  124.